package com.dgshanger.sanhxiaofeisc.mvp.presenter

import android.text.TextUtils
import com.dgshanger.sanhxiaofeisc.mvp.contract.EditNicknameContract
import com.dgshanger.sanhxiaofeisc.mvp.model.EditNicknameModel
import com.xx.baseuilibrary.mvp.BaseRxMvpPresenter
import com.xx.baseutilslibrary.network.rx.RxHttpObserver

/**
 * EditNicknamePresenter
 * 沉迷学习不能自拔
 * Describe：
 * Created by 雷小星🍀 on 2018/4/20 15:31.
 */

class EditNicknamePresenter : BaseRxMvpPresenter<EditNicknameContract.Model, EditNicknameContract.View>(), EditNicknameContract.Presenter {

    override fun editNickname() {

        val nickname = getView()!!.nickname

        if (TextUtils.isEmpty(nickname)) {
            getView()?.showToast("请输入昵称")
            return
        }

        getModel().editNickname(nickname, object : RxHttpObserver<Any>() {
            override fun onLoadingStart() {
                getView()?.showLoadingDialog()
            }

            override fun onLoadingFinish() {
                getView()?.dismissLoadingDialog()
            }

            override fun onCompleted(msg: String?, entity: Any?) {
                getView()?.showToast(msg)
                getView()?.finishActivity()
            }

            override fun onError(error: String?) {
                getView()?.showToast(error)
            }

        })
    }

    override fun createModel(): EditNicknameContract.Model = EditNicknameModel()
}
